package com.coderman.daoclient.connections;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * Created by ${fanchunshuai} on 2017-7-27.
 *
 * @version: V1.0
 * @Desc:
 * @Copyright (c) 2017 58到家-版权所有
 */
public class DBConfig {

    private static Properties properties = new Properties();

    private String jdbcDriver;
    private String url;
    private String password;
    private String user;
    private String maxPoolSize;
    private String minPoolSize;

    public DBConfig(){
        getDBProperties();
    }


    private  void getDBProperties(){
        try {
            //返回读取指定资源的输入流
            InputStream is= DBConfig.class.getClassLoader().getResourceAsStream("jdbc.properties");
            properties.load(is);
            // 1. 准备获取连接的 4 个字符串: user, password, url, jdbcDriver
            String user = properties.getProperty("user");
            String password = properties.getProperty("password");
            String url= properties.getProperty("url");
            String jdbcDriver= properties.getProperty("jdbcDriver");
            String maxPoolSize = properties.getProperty("maxPoolSize");
            String minPoolSize = properties.getProperty("minPoolSize");
            System.out.println(maxPoolSize+"-----"+minPoolSize);
            this.setUser(user);
            this.setUrl(url);
            this.setPassword(password);
            this.setJdbcDriver(jdbcDriver);
            this.setMaxPoolSize(maxPoolSize);
            this.setMinPoolSize(minPoolSize);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static Properties getProperties() {
        return properties;
    }

    public static void setProperties(Properties properties) {
        DBConfig.properties = properties;
    }

    public String getJdbcDriver() {
        return jdbcDriver;
    }

    public void setJdbcDriver(String jdbcDriver) {
        this.jdbcDriver = jdbcDriver;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getUser() {
        return user;
    }

    public void setUser(String user) {
        this.user = user;
    }

    public String getMaxPoolSize() {
        return maxPoolSize;
    }

    public void setMaxPoolSize(String maxPoolSize) {
        this.maxPoolSize = maxPoolSize;
    }

    public String getMinPoolSize() {
        return minPoolSize;
    }

    public void setMinPoolSize(String minPoolSize) {
        this.minPoolSize = minPoolSize;
    }
}
